﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using transportsystem.DTO;
using UTIL;

namespace transportsystem.DAO
{
    public class DaiLyDAO
    {
        public static DataTable getDaiLyList()
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_DanhSachDaiLy";
            DataSet ds = SqlDataAccessHelper.LoadData(procName);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }

        public static DataTable getKhuVucList()
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_DanhSachKhuVuc";
            DataSet ds = SqlDataAccessHelper.LoadData(procName);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }

        public static DataTable getDaiLyTheoKhuVucList(string khuvuc)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_DanhSachDaiLyTheoKhuVuc N'" + khuvuc + "'";
            DataSet ds = SqlDataAccessHelper.LoadData(procName);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }

        public static int thaoTacDaiLy(params SqlParameter[] Params)
        {

            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_ThaoTacDaiLy";
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, Params);
            if (ds != null)
                return 1;
            return 0;

        }
        public static int CapNhatDaiLy1(params SqlParameter[] Params)
        {

            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_CapNhatDaiLy1";
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, Params);
            if (ds != null)
                return 1;
            return 0;

        }
        public static int CapNhatDaiLy2(params SqlParameter[] Params)
        {

            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_CapNhatDaiLy2";
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, Params);
            if (ds != null)
                return 1;
            return 0;

        }
        public static bool deleteDaiLy(DaiLy dl)
        {
            SqlCommand cmd = SqlDataAccessHelper.CreateCommand("sp_XoaDaiLy");
            cmd.Parameters.Add("@madaily", SqlDbType.Int).Value = dl.Madaily;
            return SqlDataAccessHelper.ExecCmd(cmd);
        }

        public static DataSet getDaiLy2(params SqlParameter[] Params)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_TraCuuDaiLy2";
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, Params);
            if (ds != null)
                return ds;
            return null;
        }

        public static DataTable getDaiLyListVu()
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_TraCuuDaiLy";
            DataSet ds = SqlDataAccessHelper.LoadData(procName);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }
        //tcp bo sung
        public static DataTable layDanhSachDaiLy()
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_DanhSachDaiLy";
            DataSet ds = SqlDataAccessHelper.LoadData(procName);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }

    }
}
